package com.bnyy.medicalHousekeeper.fragment;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bnyy.medicalHousekeeper.R;
import com.bnyy.medicalHousekeeper.base.BaseFragmentImpl;
import com.just.agentweb.AgentWeb;
import com.just.agentweb.WebChromeClient;

import butterknife.BindView;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2023/2/7
 **/
public class HtmlArticleFragment extends BaseFragmentImpl {
    //    @BindView(R.id.web_view)
//    WebView webView;
    @BindView(R.id.weblayout)
    LinearLayout weblayout;

    @Override
    public int getLayoutId() {
        return R.layout.layout_web_view;
    }

    public static HtmlArticleFragment getInstance(String url) {
        HtmlArticleFragment fragment = new HtmlArticleFragment();
        Bundle bundle = new Bundle();
        bundle.putString("url", url);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        Bundle bundle = getArguments();
        if (bundle != null) {
            String url = bundle.getString("url", "");

            AgentWeb.with(this)//传入Activity
                    .setAgentWebParent(weblayout, new LinearLayout.LayoutParams(-1, -1))//传入AgentWeb 的父控件 ，如果父控件为 RelativeLayout ， 那么第二参数需要传入 RelativeLayout.LayoutParams
                    .useDefaultIndicator()// 使用默认进度条
                    .setWebChromeClient(new WebChromeClient() {

                    })
                    .createAgentWeb()//
                    .ready()
                    .go(url);

//            AgentWeb agentWeb = AgentWeb.with(this)//传入Activity
//                    .setAgentWebParent(weblayout, new LinearLayout.LayoutParams(-1, -1))//传入AgentWeb 的父控件 ，如果父控件为 RelativeLayout ， 那么第二参数需要传入 RelativeLayout.LayoutParams
//                    .useDefaultIndicator()// 使用默认进度条
//                    .createAgentWeb()//
//                    .ready()
//                    .get();
//
//            agentWeb.getUrlLoader().loadData(content, "text/html", "utf-8");
        }
    }
}
